<template>
  <div class="content">
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
    >
      <el-form-item label="订单完成时间">
        <BiDatePicker
          v-model="formInline.pay_time"
          style="width:230px;"
          clearable
          size="small"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
        <!-- :default-time="['00:00:00', '23:59:59']" -->
      </el-form-item>
      <el-form-item label="订单类型">
        <el-select
          v-model="formInline.order_type"
          placeholder="请选择订单类型"
          clearable
        >
          <el-option
            v-for="(item,index) in orderTypeList"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="退款时间">
        <BiDatePicker
          v-model="formInline.refund_time"
          style="width:230px;"
          clearable
          size="small"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
        <!-- :default-time="['00:00:00', '23:59:59']" -->
      </el-form-item>
      <el-form-item>
        <el-button
          :loading="loading"
          type="primary"
          style="margin-left:10px;"
          @click="startSearch"
        >查询</el-button>
      </el-form-item>
    </el-form>
    <div class="table-table">

      <BiTable
        :loading="loading"
        :data="tableData"
        size="medium"
        :column="tableColums"
        fixed="sticky"
        fixed-offset="50"
        pagination
        layout="total, prev, pager, next"
        :auto-scroll="false"
        :total="page_info.total"
        :page.sync="page_info.page"
        :limit.sync="page_info.page_size"
        @pagination="handlePageChange"
      >
        <template v-slot:dy_refund_no="{ row }">
          <a
            style="color:#06C261;"
            @click="goOrderPage(row)"
          >{{ row.dy_refund_no }}</a>
        </template>
        <template v-slot:refund_status="{ row }">
          <div class="colorStatus">
            <p
              v-if="row.refund_status==1"
              class="indeter"
            >退款中</p>
            <p
              v-if="row.refund_status==2"
              class="success"
            >退款成功</p>
            <p
              v-if="row.refund_status==3"
              class="fail"
            >退款失败</p>
          </div>
        </template>
      </BiTable>
    </div>
  </div>
</template>

<script>
import { refundRecord } from '@/api/userPage'
import { formatNumber } from '@/utils/index'
import { mapState } from 'vuex'

export default {
  components: {},
  props: ['rowInfo'],
  computed: {
    ...mapState('common', ['orderTypeList'])
  },
  data() {
    return {
      formInline: {
        pay_time: [],
        refund_time: [],
        order_type: '',
        pay_time_start: '',
        pay_time_end: '',
        refund_time_start: '',
        refund_time_end: '',
        member_id: ''
      },
      loading: false,
      tableData: [],
      tableColums: [
        {
          label: '订单号',
          prop: 'order_no'
        },

        {
          label: '订单渠道',
          prop: 'channel_name',
          width: '200',
          render: (h, { row }) => {
            return (
              <div>
                <p>{row.channel_name}</p>
                <p>{row.channel_id}</p>
              </div>
            )
          }
        },
        {
          label: '充值视频',
          prop: 'playlet_title'
        },
        {
          label: '充值集数',
          prop: 'chapter_title'
        },
        {
          label: '订单类型',
          prop: 'product_name'
        },
        {
          label: '订单完成时间',
          prop: 'pay_time',
          width: '160'
        },
        {
          label: '充值金额',
          prop: 'amount',
          render: (h, { row }) => {
            return <span>{formatNumber(row.amount)} </span>
          }
        },
        {
          label: '退款金额',
          prop: 'refund_amount',
          render: (h, { row }) => {
            return <span>{formatNumber(row.refund_amount)} </span>
          }
        },
        {
          label: '退款单号',
          prop: 'dy_refund_no',
          width: '200',
          slotScope: true
        },
        {
          label: '退款状态',
          prop: 'refund_status',
          width: 100,
          slotScope: true
        },
        {
          label: '退款时间',
          prop: 'refund_time',
          width: '160'
        },
        {
          label: '权益调整',
          prop: 'order_type',
          render: (h, { row }) => {
            if (row.order_type == 1) {
              return (
                <div>
                  <p>减少喵币:{row.refund_coin}</p>
                  <p>减少赠币:{row.refund_free_coin}</p>
                </div>
              )
            } else if (row.order_type == 2) {
              return <p>本笔订单会员有效期取消</p>
            } else if (row.order_type == 3) {
              return <p>本笔订单解锁短剧自动失败</p>
            } else {
              return <span> </span>
            }
          },
          width: '160'
        }
      ],
      page_info: {
        page: 1,
        page_size: 20,
        total: 0
      }
    }
  },
  mounted() {
    this.clickSearch('type')
  },
  methods: {
    goOrderPage(row) {
      this.$router.push({ path: '/order/refund', query: { id: row.order_no } })
    },
    handlePageChange(page) {
      this.page_info.page = page.page
      this.clickSearch()
    },
    startSearch() {
      this.page_info.page = 1
      this.clickSearch()
    },
    onSubmit() {},
    clickSearch(type) {
      this.loading = true
      const data = {
        order_type: this.formInline.order_type,
        pay_time_start: (this.formInline.pay_time && this.formInline.pay_time[0]) || '',
        pay_time_end: (this.formInline.pay_time && this.formInline?.pay_time[1]) || '',
        refund_time_start: (this.formInline.refund_time && this.formInline.refund_time[0]) || '',
        refund_time_end: (this.formInline.refund_time && this.formInline?.refund_time[1]) || '',
        member_id: this.rowInfo.member_id
      }
      refundRecord({ ...data, ...this.page_info }).then((res) => {
        if (res.status_code === 1) {
          this.tableData = res.data.data
          this.page_info = res.data.page_info
          !type ? this.$message.success(res.msg) : ''
        }
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>